import time
import datetime
# time 模块
shijianchou=time.time()
print(shijianchou)

structtime=time.localtime(shijianchou)

print(structtime)

format_time=time.strftime("%Y/%m/%d %H:%M:%S")
print(format_time)

# datetime模块
# 构造一个datetime
dt=datetime.datetime(2020,1,1,15,3,45)
print(dt)

# 获取当前时间
now=datetime.datetime.now()
print(now)

# 将当前时间转换为时间戳 timestamp
st=now.timestamp()
print(st)

# 将时间戳转换为datetime
datetime1=datetime.datetime.fromtimestamp(st)
print(datetime1)

# 将str转换为datetime
cday = datetime.datetime.strptime('2015/6/1 18:19:59','%Y/%m/%d %H:%M:%S')
print(cday)

# 将datetime转换为str
now=datetime.datetime.now()
str_now=now.strftime('%Y/%m/%d %H:%M:%S')
print(str_now)
